package concurrency.weakreference;

import java.util.Map;
import java.util.WeakHashMap;

/**
 * Created by Tzachi on 18/10/2014.
 */
public class ErrorSender {
    // we use WeakHashMap in order not to overload the number of "same" exceptions sent to the "support team"
    Map<DBRuntimeException, Void> map = new WeakHashMap<>();
    private String[] emails;

    // for example we will use aspect here to send the message after an exception occured
    public void afterEx(DBRuntimeException ex) {
        if (map.containsKey(ex)) {
            return;
        }
        for (String email : emails) {
            System.out.println("Sending email to " + email);
        }
        map.put(ex, null);
    }

}